Low level memory management

From Cppreference

Jump to: navigation, search

Contents

[edit] Allocation

The new expression is a language builtin which is the only way to initialize objects initialize objects in dynamically obtained memory. The memory is acquired by an operator new, new[] (allocation functions).

[edit] Deallocation

The delete expression is used to destruct objects previously initialized by the new expression and deallocate memory after that. For deallocation the delete expression uses operator delete, delete[] (deallocation functions).

Note, that it is possible to explicitly call the destructor of an object and deallocation function separately, if required.

[edit] Miscellaneous

The <new> header contains declarations of default allocation and deallocation functions (note that these functions are implicitly defined in each translation unit). Also several utility functions, types and objects are declared

Classes
bad_alloc
exception thrown when memory allocation fails
(class)
bad_array_new_length (C++11)
exception thrown on allocation of array with greater than
implementation supported, or negative length
(class)
nothrow_t
tag type used to select an non-throwing allocation function
(class)
Types
new_handler (C++11)
function pointer type, used in set_new_handler()
(class)
Functions
set_new_handler (C++11)
sets a function which is called when an allocation function
fails to obtain more memory to the free memory pool
(function)
Objects
nothrow
an object of type nothrow_t used to select an non-throwing allocation function
(constant)
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
In other languages